<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Store
 *
 * @method static find($store_id)
 * @property int $id
 * @property string|null $title 商铺名字
 * @property int $admin_id 商铺联系人
 * @property string $province
 * @property string $city
 * @property string|null $district
 * @property string $detailed_address 街道、门牌号等详细信息
 * @property int|null $recommend_user_id 推荐人id
 * @property int|null $sold_num 销量
 * @property string|null $status 1：待审核；2：正常；3：关闭。
 * @property string|null $service_mobile 商家服务电话
 * @property string|null $open_start
 * @property string|null $open_end
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \App\Models\Admin $admin
 * @property-read \App\Models\User|null $recommend
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereAdminId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereCity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereDetailedAddress($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereDistrict($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereOpenEnd($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereOpenStart($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereProvince($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereRecommendUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereServiceMobile($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereSoldNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Store extends Model
{
    protected $guarded = [];

    //分页返回商铺列表数据
    function get_store($where = [],$limit = LIMIT){
        return self::with(['admin'=>function($query){
            return $query->select('id','phone','nickname');
        }])->where($where)->orderBy('stores.id','desc')
                    ->limit($limit)->paginate();
    }

    //商铺的推荐人
    function recommend() {
        return $this->belongsTo('App\Models\User','recommend_user_id','id');
    }

    //商铺联系人
    function admin() {
        return $this->belongsTo('App\Models\Admin');
    }
}
